import {Component, OnInit, OnDestroy} from "@angular/core";
import {ActivatedRoute, Router} from "@angular/router";
import {RoleService, Role} from "./role.service";
@Component({
    templateUrl: 'app/modules/role/html/role.edit.html',
})
export class RoleEditComponent implements OnInit,OnDestroy {
    role:Role;
    private sub:any;

    constructor(private route:ActivatedRoute,
                private router:Router,
                private service:RoleService) {
    }

    ngOnInit() {
        this.sub = this.route.params.subscribe(params => {
            let id = +params['id']; // (+) converts string 'id' to a number
            this.service.getRole(id).then(role => this.role = role);
        });
    }

    ngOnDestroy() {
        this.sub.unsubscribe;
    }

    goToRoles() {
        this.router.navigate(['/roles']);
    }
}